/*
 * fs.h
 *
 *  Created on: 2016-11-17
 *      Author: m
 */

#ifndef SRC_INCLUDE_FS_FS_H_
#define SRC_INCLUDE_FS_FS_H_
#include "type.h"

typedef struct drv_map {
    int drv_pid;
}DRV_INFO;

#define MAX_FILENAME_LEN    (12)

#define IT_MASK         (0xF000)
#define I_REGULAR       (0x8000)
#define I_BLOCK_SPECIAL (0x6000)
#define I_DIRECTORY     (0x4000)
#define I_CHAR_SPECIAL  (0x2000)
#define I_NAMED_PIPE    (0x1000)

typedef struct inode {
    u32 access_mode;
    u32 file_size;
    u32 data_start_sect;
    u32 data_sect_cnt;
    u32 reserved[4];
} INODE;

typedef struct {
    int begin_sect;
    int end_sect;
} SECT_INFO;

typedef struct supper_block{
    u16 magic;
    u16 fs_version;
    u32 inode_cnt; //这里固定用一个扇区表示哪些inode有效，所以其最多有512*8=4096个inode
    u32 sect_cnt;  //BOOT_MINOR所在分区的扇区数,这里为40257
    u32 inode_map_sect_cnt; //inode_cnt的注释已经写过了,这里固定为1                               关键点：标示哪些inode有效
    u32 sect_map_sect_cnt;  //用一个bit位来表示一个扇区是否被使用，因此有 (40257 + 4095)/(512*8)=10  关键点：标示哪些扇区有效
    u32 inode_arr_sect_cnt; //(4096*sizeof(inode)+511)/512=(4096*32+511)/512=256
    u32 idx_1st_data_sect;  //第一个数据扇区的索引=sect_cnt(boot)+sect_cnt(sb)+sect_cnt(inode-map)+sect_cnt(sect_map)+sect_map(inode_arr)=1+1+1+10+256=269
    u32 idx_root_inode; //固定为1
    u32 inode_size; //固定为32
    SECT_INFO sect_info_sb;
    SECT_INFO sect_info_inode_map;
    SECT_INFO sect_info_sect_map;
    SECT_INFO sect_info_inode_arr;
    SECT_INFO sect_info_data;
} SUPPER_BLOCK;

typedef struct dir_entry {
    int  inode_idx;
    char name[MAX_FILENAME_LEN]; /**< Filename */
} DIR_ENTRY;

typedef struct file_desc {
    int fd_mode;
    int fd_cur_rw_pos;
    INODE* pi;
} FILE_DESC;

void task_fs();
#endif /* SRC_INCLUDE_FS_FS_H_ */
